# ~~~
# ####################################################################
# Description:  MachinekitHALMANAGED-HALComponent.cmake.in
#
#               This file, 'MachinekitHALMANAGED-HALComponent.cmake.in',
#               implements build system
#               rules for Machinekit-HAL project
#
# Copyright (C) 2021    Jakub Fišer  <jakub DOT fiser AT eryaf DOT com>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
#
# #####################################################################
# ~~~

# Set the variable prefix of this file to 'MHMRC_'

set(MHMRC_targets_paths
    "[
    {
        \"target\":\"@MACHINEKIT_HAL_NAMESPACE@::runtime_config\",
        \"file\":\"${CMAKE_CURRENT_LIST_DIR}/MachinekitHALRuntimeConfigTarget.cmake\"
    },
    {
        \"target\":\"@MACHINEKIT_HAL_NAMESPACE@::mkini\",
        \"file\":\"${CMAKE_CURRENT_LIST_DIR}/MachinekitHALMKIniTarget.cmake\"
    },
    {
        \"target\":\"@MACHINEKIT_HAL_NAMESPACE@::hal_api\",
        \"file\":\"${CMAKE_CURRENT_LIST_DIR}/MachinekitHALHALAPITarget.cmake\"
    },
    {
        \"target\":\"@MACHINEKIT_HAL_NAMESPACE@::runtime_api\",
        \"file\":\"${CMAKE_CURRENT_LIST_DIR}/MachinekitHALRuntimeAPITarget.cmake\"
    },
    {
        \"target\":\"Machinekit::HAL::rtapi_compat\",
        \"file\":\"${CMAKE_CURRENT_LIST_DIR}/MachinekitHALRuntimeCompatTarget.cmake\"
    },
    {
        \"target\":\"@MACHINEKIT_HAL_NAMESPACE@::managed_runtime\",
        \"file\":\"${CMAKE_CURRENT_LIST_DIR}/MachinekitHALManagedRuntimeTarget.cmake\"
    },
]")

set(MHMRC_symbol_visibility_function
    "${CMAKE_CURRENT_LIST_DIR}/MachinekitHALSymbolVisibilityFunction.cmake")

string(JSON MHMRC_targets_paths_length LENGTH "${MHMRC_targets_paths}")
math(EXPR MHMRC_targets_paths_length "${MHMRC_targets_paths_length} - 1"
     OUTPUT_FORMAT DECIMAL)

foreach(_index RANGE 0 ${MHMRC_targets_paths_length} 1)
  string(JSON MHMRC_name GET "${MHMRC_targets_paths}" ${_index} "target")
  string(JSON MHMRC_path GET "${MHMRC_targets_paths}" ${_index} "file")
  if(NOT EXISTS "${MHMRC_path}")
    set(${CMAKE_FIND_PACKAGE_NAME}_FOUND False)
    set(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE
        "File \"${MHMRC_path}\" is missing!")
    return()
  endif()
  if(NOT TARGET "${MHMRC_name}")
    include("${MHMRC_path}")
  endif()
endforeach()

include("${MHMRC_symbol_visibility_function}")
